package com.weiyi.chat.presenter;

import android.os.Environment;

import com.google.gson.Gson;
import com.weiyi.chat.api.ILogin;
import com.weiyi.chat.api.IRegister;
import com.weiyi.chat.common.MyStringCallBack;
import com.weiyi.chat.domain.User;
import com.weiyi.chat.ui.activity.LoginActivity;
import com.weiyi.chat.ui.activity.RegisterActivity;
import com.weiyi.chat.utils.MyReusouce;
import com.weiyi.chat.utils.ToastUtil;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;

import static com.weiyi.chat.utils.MyReusouce.REGISTER_URL;
import static com.weiyi.chat.utils.MyReusouce.VIRIFY_CODE_URL;

/**
 * Created by Lee on 2017/8/24 0024.
 */

public class RegisterPresenter implements IRegister.presenter {


    private RegisterActivity mView;

    public RegisterPresenter(RegisterActivity registerActivity) {
        mView = registerActivity;
    }

    @Override
    public void registerAccount(String user_phone, String psw, String real_name, String id_number) {

        OkHttpUtils.post()
                .url(MyReusouce.REGISTER_URL)
                .addParams("account", user_phone)
                .addParams("mobile", user_phone)
                .addParams("owner", real_name)
                .addParams("pass", psw)
                .addParams("id_number", id_number)
                .build()
                .execute(new MyStringCallBack(mView) {
                    @Override
                    public void onRequestSucess(String response) {
                        mView.onRegisterSucess();
                    }

                    @Override
                    public void onRequstFail(String errorInfo) {
                        mView.showError(errorInfo);
                    }
                });
    }

    @Override
    public void loadingDatasFromCache() {

    }
}
